def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True

def closest_prime(num):
    if is_prime(num):
        return num

    lower = num - 1
    upper = num + 1

    while True:
        if is_prime(lower):
            return lower
        elif is_prime(upper):
            return upper
        else:
            lower -= 1
            upper += 1

def word_to_number(word):
    numbers = {"zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, 
               "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9}
    return numbers[word]

def main():
    words = input().split()
    
    if len(words) != 3:
        print("Wrong input")
        return

    try:
        number = int("".join(str(word_to_number(word)) for word in words))
        if 100 <= number <= 999:
            print(closest_prime(number))
        else:
            print("Wrong input")
    except ValueError:
        print("Wrong input")

if __name__ == "__main__":
    main()

